package com.dfbz.springboot_project.controller;

import com.sun.org.apache.xpath.internal.operations.Mod;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("common")
public class LoginController {
    @RequestMapping("toLogin")
    public ModelAndView toLogin(){
        return new ModelAndView("/html/login.html");
    }
    @RequestMapping("login")
    public ModelAndView login(HttpServletRequest request){
        String failure = (String) request.getAttribute("shiroLoginFailure");
        if (failure!=null){
            if (UnknownAccountException.class.getName().equals(failure)){
                System.out.println("账号不存在");
                //return new ModelAndView("/html/login.html");
            }
            else if (IncorrectCredentialsException.class.getName().equals(failure)){
                System.out.println("密码错误");
                //return new ModelAndView("/html/login.html");
            }
            else {
                System.out.println("其他异常");
                //return new ModelAndView("/html/login.html");
            }
        }
        return new ModelAndView("/html/index.html");
    }
    @RequestMapping("index")
    public ModelAndView index(){
        return new ModelAndView("/html/index.html");
    }
    @RequestMapping("nopower")
    public ModelAndView nopower(){
        return new ModelAndView("/html/nopower.html");
    }
}
